package org.alis.smallcc.exportexcel.controller;

import org.alis.smallcc.exportexcel.entey.Student;
import org.alis.smallcc.exportexcel.util.ExportExcelExtUtil;
import org.alis.smallcc.exportexcel.util.ExportExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/**
* @project: ExportController.java
* @description: 导出Excel
* @author: smallcc
* @create: 2019/9/10 :22:49
*/
@Controller
@RequestMapping(value = "/export")
public class ExportController {
    @RequestMapping(value = "/excel")
    public void excel(HttpServletResponse response) throws FileNotFoundException {
        // 准备数据
        List<Student> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new Student(111,"张三asdf","男"));
            list.add(new Student(111,"李四asd","男"));
            list.add(new Student(111,"王五","女"));
        }
        String[] columnNames = { "ID", "姓名", " 性别"};
        String fileName = "测试1";
        ExportExcelExtUtil<Student> util = new ExportExcelExtUtil<>();
        util.exportExcel(fileName, fileName, columnNames, list, response, ExportExcelUtil.EXCEL_FILE_2003);

    }
}
